import request from '@/utils/request'

/**
 *
 * @param {string} mobile -手机号
 * @param {string} code  -验证码
 * @returns
 */
export const loginAPI = (mobile, code) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}

export const getCodeAPI = (mobile) => {
  return request({
    url: `/v1_0/sms/codes/${mobile}`
  })
}

export const getUserInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}

/**
 *获取用户资料
 * @returns promise
 */
export const getUserProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}

/**
 *修改客户信息 修改那个传那个
 * @param {*} data {name gender,brithday}
 * @returns promise
 */
export const editUserProfileAPI = (data) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data
  })
}

/**
 *上传头像
 * @param {*} file 图片的文件对象
 * @returns Promise
 */
export const upLoadPhoto = (file) => {
  const fm = new FormData()
  fm.append('photo', file)
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: fm
  })
}
